/**************************************************************************//**
 * @file     sys.c
 * @version  V1.00
 * $Revision: 2 $
 * $Date: 16/03/24 19:02 $
 * @brief    Panchip series SYS driver source file
 *
 * @note
 * Copyright (C) 2016 Panchip Technology Corp. All rights reserved.
*****************************************************************************/

#include "PanSeries.h"
#include "pan_sys.h"

/** @addtogroup Panchip_Device_Driver Panchip Device Driver
  @{
*/

/** @addtogroup Panchip_SYS_Driver SYS Driver
  @{
*/


/** @addtogroup Panchip_SYS_EXPORTED_FUNCTIONS SYS Exported Functions
  @{
*/
#define __nop()     __asm("nop")
void SYS_delay_10nop(uint32_t u32NopCnt)
{
	while(u32NopCnt--)
	{
		__nop();
		__nop();
		__nop();
		__nop();
		__nop();
		__nop();
		__nop();
		__nop();
		__nop();
	}
}
///**
//  * @brief  This function clear the selected system reset source
//  * @param[in]  u32Src is system reset source
//  * @return None
//  */
//void SYS_ClearResetSrc(uint32_t u32Src)
//{
//    SYS->RSTSTS |= u32Src;
//}

///**
//  * @brief  This function get Brown-out detector output status
//  * @return 0: System voltage is higher than BOD_VL setting or BOD_EN is 0.
//  *         1: System voltage is lower than BOD_VL setting.
//  *         Note : If the BOD_EN is 0, this function always return 0.
//  */
//uint32_t SYS_GetBODStatus(void)
//{
//    return (SYS->BODCTL & SYS_BODCTL_BODOUT_Msk)?1:0;
//}

///**
//  * @brief  This function get the system reset source register value
//  * @return Reset source
//  */
//uint32_t SYS_GetResetSrc(void)
//{
//    return (SYS->RSTSTS);
//}

/**
  * @brief  This function check register write-protection bit setting
  * @return 0: Write-protection function is disabled.
  *         1: Write-protection function is enabled.
  */
uint32_t SYS_IsRegLocked(void)
{
    return !(SYS->REGLCTL & SYS_REGLCTL_REGLCTL_Msk);
}

///**
//  * @brief  This function reset chip.
//  * @return None
//  */
//void SYS_ResetChip(void)
//{
//    SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk;
//}

///**
//  * @brief  This function reset CPU.
//  * @return None
//  */
//void SYS_ResetCPU(void)
//{
//    SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk;
//}

///**
//  * @brief  This function reset selected modules.
//  * @param[in]  u32ModuleIndex is module index. Including :
//  *                  - \ref ADC_RST
//  *                  - \ref ACMP_RST
//  *                  - \ref PWM0_RST
//  *                  - \ref WWDT_RST
//  *                  - \ref WDT_RST
//  *                  - \ref UART1_RST
//  *                  - \ref UART0_RST
//  *                  - \ref SPI1_RST
//  *                  - \ref SPI0_RST
//  *                  - \ref I2C0_RST
//  *                  - \ref I2C1_RST
//  *                  - \ref TMR2_RST
//  *                  - \ref TMR1_RST
//  *                  - \ref TMR0_RST
//  *                  - \ref GPIO_RST
//  *	@param[in]  u32HoldTime is Reset time hold time. It should be equals the clock of the module.
//  * @return None
//  */

//void SYS_ResetModule(uint32_t u32ModuleIndex, uint32_t u32HoldTime)
//{
//    *(volatile uint32_t *)((uint32_t)&(SYS->IPRST0) + (u32ModuleIndex>>24)) |= 1<<(u32ModuleIndex & 0x00ffffff);
//	SYS_delay_10nop(u32HoldTime);
//    *(volatile uint32_t *)((uint32_t)&(SYS->IPRST0) + (u32ModuleIndex>>24)) &= ~(1<<(u32ModuleIndex & 0x00ffffff));
//	SYS_delay_10nop(u32HoldTime);
//}




/**
  * @brief  This function configure BOD function.
  *         Configure BOD reset or interrupt mode and set Brown-out voltage level.
  *         Enable Brown-out function
  * @param[in]  i32Mode is reset or interrupt mode. Including :
  *                  - \ref SYS_BODCTL_BOD_RST_EN
  *                  - \ref SYS_BODCTL_BOD_INTERRUPT_EN
  * @param[in]  u32BODLevel is Brown-out voltage level. Including :
  *                  - \ref SYS_BODCTL_DISABLE
  *                  - \ref SYS_BODCTL_BODVL_2_67V
  *                  - \ref SYS_BODCTL_BODVL_2_4V
  *                  - \ref SYS_BODCTL_BODVL_2_15V
  * @return None
  */
//void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
//{

//    SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODRSTEN_Msk) | i32Mode;

//// // //     ANAC->RCC_CTL = (ANAC->RCC_CTL & ~ANAC_RCC_CTL_BODVL_Msk) | u32BODLevel;
//// // //     ANAC->RCC_CTL |= ANAC_RCC_CTL_BODEN_Msk;
//}

/**
  * @brief  This function disable BOD function.
  * @return None
  */
void SYS_DisableBOD(void)
{
//     ANAC->RCC_CTL &= ~ANAC_RCC_CTL_BODEN_Msk;
}



/*@}*/ /* end of group Panchip_SYS_EXPORTED_FUNCTIONS */

/*@}*/ /* end of group Panchip_SYS_Driver */

/*@}*/ /* end of group Panchip_Device_Driver */

/*** (C) COPYRIGHT 2016 Panchip Technology Corp. ***/
